package org.scboy.rbac.controller;

import org.scboy.common.annotation.Menu;
import org.scboy.common.annotation.Permission;
import org.scboy.common.request.Result;
import org.scboy.rbac.service.RbacSystemGroupService;
import org.scboy.utils.entitys.coobi.Model;
import org.scboy.utils.entitys.coobi.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rbac/systemgroup")
@Menu("权限管理系统.系统分组")
public class RbacSystemGroupController {

	@Autowired
	RbacSystemGroupService service;
	
	/**
	 * 分页查询系统分组列表
	 * 
	 * @param request
	 * @return
	 */
	@PostMapping("page")
	@Permission("分页查询系统分组列表")
	public Result page(@RequestBody Model params) {
		Page page = service.page(params);
		return Result.Success(page.getData(), page.getCount());
	}

	/**
	 * 新增系统分组
	 * 
	 * @param request
	 * @return
	 */
	@PostMapping("add")
	@Permission("新增系统分组")
	public Result add(@RequestBody Model params) {
		if (service.add(params)) {
			return Result.Success("RBAC_SYSTEM_GROUP_ADD_SUCCESS");
		} else {
			return Result.Error("RBAC_SYSTEM_GROUP_ADD_ERROR");
		}
	}

	/**
	 * 更新系统分组
	 * 
	 * @param request
	 * @return
	 */
	@PutMapping("update")
	@Permission("更新系统分组")
	public Result update(@RequestBody Model params) {
		if (service.update(params)) {
			return Result.Success("RBAC_SYSTEM_GROUP_UPDATE_SUCCESS");
		} else {
			return Result.Error("RBAC_SYSTEM_GROUP_UPDATE_ERROR");
		}
	}

	/**
	 * 删除系统分组
	 * 
	 * @param request
	 * @param id
	 * @return
	 */
	@DeleteMapping("delete")
	@Permission("删除系统分组")
	public Result delete(String id) {
		if (service.delete(id)) {
			return Result.Success("RBAC_SYSTEM_GROUP_DELETE_SUCCESS");
		} else {
			return Result.Error("RBAC_SYSTEM_GROUP_DELETE_ERROR");
		}
	}

	/**
	 * 获取启用的系统分组
	 * 
	 * @param request
	 * @return
	 */
	@GetMapping("list")
	@Permission("获取启用的系统分组")
	public Result list() {
		return Result.Success(service.list(), "");

	}

	/**
	 * 获取系统分组信息
	 * 
	 * @param request
	 * @param id
	 * @return
	 */
	@GetMapping("get")
	@Permission("获取系统分组信息")
	public Result get(String id) {
		return Result.Success(service.get(id), "");
	}

	@PutMapping("sort")
	@Permission("升序降序")
	public Result sort(String id,int type) {
		boolean check=service.sort(id,type);
		if(check) {
			return Result.Success("RBAC_SYSTEM_GROUP_SORT_SUCCESS");
		}else {
			return Result.Error("RBAC_SYSTEM_GROUP_SORT_ERROR");
		}
	}
	
}
